﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace Domain.DAL
{
    public class ReportsAndStatisticsDAO
    {
        #region Private Fields

        private Database db;

        #endregion

        #region Constructors

        public ReportsAndStatisticsDAO(Database theDatabase)
        {
            this.db = theDatabase;
        }

        #endregion

        #region Public Methods

        public DataSet ReportByProductType(string reportDateFrom, string reportDateTo)
        {
            DataSet ds = new DataSet();

            try
            {
                ds = this.db.ExecuteDataSet("sp_rptReportByProductType", reportDateFrom, reportDateTo);
            }
            catch (Exception)
            {
                ds.Dispose();
                throw;
            }

            return ds;
        }

        public DataSet ReportByProductTypeDetails(string productTypeID, string reportDateFrom, string reportDateTo)
        {
            DataSet ds = new DataSet();

            try
            {
                ds = this.db.ExecuteDataSet("sp_rptReportByProductTypeDetails", productTypeID, reportDateFrom, reportDateTo);
            }
            catch (Exception)
            {
                ds.Dispose();
                throw;
            }

            return ds;
        }

        public DataSet GeneralReport(string productTypeID, string repairingTypeID, string repairer, string reportDateFrom, string reportDateTo)
        {
            DataSet ds = new DataSet();

            try
            {
                ds = this.db.ExecuteDataSet("sp_rptGeneralReport", productTypeID, repairingTypeID, repairer, reportDateFrom, reportDateTo);
            }
            catch (Exception)
            {
                ds.Dispose();
                throw;
            }

            return ds;
        }


        #endregion

        #region Public Static Methods

        public static ReportsAndStatisticsDAO GetInstance()
        {
            return EnterpriseLibraryContainer.Current.GetInstance<ReportsAndStatisticsDAO>();
        }

        #endregion
    }
}
